$(function () {
    var first = '<li>\n' +
        '                        <a _href="gateway-list.html">\n' +
        '                            <i class="iconfont layui-icon">&#xe656;</i>\n' +
        '                            <cite>网关面板</cite>\n' +
        '                        </a>\n' +
        '                    </li>';


    $.ajax({
        url: baseUrl + "/servcieGateway/list/distinct?likeComment=",
        data: "",
        contentType: 'application/json;charset=utf-8',
        dataType: "JSON",
        async: false,
        type: "GET",
        success: function (respData) {
            if (respData.respCode === '0000') {
                try {
                    var seconds = '';
                    respData.data.items.forEach(function (val_, idx_) {
                        seconds += getGatewayLi(val_);
                    });

                    $("#gateWayConfUl").html(first + seconds);

                    var alertUserHtml = getAlertUserHtml(respData.data.items);
                    var serverGroupAlertUserHtml = getServerGroupAlertUserHtml(respData.data.items);

                    $("#gateWayAlertConfUrl").html(alertUserHtml + serverGroupAlertUserHtml);
                } catch (e) {

                }
            } else {
                layer.msg(respData.respDesc, {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    //do something
                });
            }
        }
    });
});


function getServerGroupAlertUserHtml(gatewayDatas) {
    var lis = '';
    gatewayDatas.forEach(function (val_, idx_) {
        lis += getServerGroupAlertUserLi(val_);
    });

    var serverGroupAlertUserFirst = '<li>\n' +
        '    <a _href="javascript:;">\n' +
        '        <i class="iconfont layui-icon">&#xe716;</i>\n' +
        '    <cite>服务组告警配置</cite>\n' +
        '    </a><ul class="sub-menu">' + lis + '</ul>' +
        '    </li>';


    return serverGroupAlertUserFirst;
}


function getServerGroupAlertUserLi(gatewayData) {

    var gatewayLi = '<li>\n' +
        '                        <a href="javascript:;">\n' +
        '                            <i class="iconfont layui-icon">&#xe653;</i>\n' +
        '                            <cite>' + gatewayData.comment + '</cite>\n' +
        '                            <i class="iconfont nav_right">&#xe697;</i>\n' +
        '                        </a>\n' +
        '                        <ul class="sub-menu">\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-service-group-list.html?env=dev&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>dev</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-service-group-list.html?env=fat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>fat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-service-group-list.html?env=uat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>uat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-service-group-list?env=pro&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>pro</cite>\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '\n' +
        '                        </ul>\n' +
        '                    </li>';

    return gatewayLi;
}

function getAlertUserHtml(gatewayDatas) {
    var lis = '';
    gatewayDatas.forEach(function (val_, idx_) {
        lis += getAlertUserLi(val_);
    });

    var alertUserFirst = '<li>\n' +
        '    <a _href="javascript:;">\n' +
        '        <i class="iconfont layui-icon">&#xe770;</i>\n' +
        '    <cite>联系人面板</cite>\n' +
        '    </a><ul class="sub-menu">' + lis + '</ul>' +
        '    </li>';

    return alertUserFirst;
}


function getAlertUserLi(gatewayData) {

    var gatewayLi = '<li>\n' +
        '                        <a href="javascript:;">\n' +
        '                            <i class="iconfont layui-icon">&#xe653;</i>\n' +
        '                            <cite>' + gatewayData.comment + '</cite>\n' +
        '                            <i class="iconfont nav_right">&#xe697;</i>\n' +
        '                        </a>\n' +
        '                        <ul class="sub-menu">\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-user-list.html?env=dev&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>dev</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-user-list.html?env=fat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>fat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-user-list.html?env=uat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>uat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="alert-user-list.html?env=pro&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>pro</cite>\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '\n' +
        '                        </ul>\n' +
        '                    </li>';

    return gatewayLi;
}


function getGatewayLi(gatewayData) {

    var gatewayLi = '<li>\n' +
        '                        <a href="javascript:;">\n' +
        '                            <i class="iconfont layui-icon">&#xe653;</i>\n' +
        '                            <cite>' + gatewayData.comment + '</cite>\n' +
        '                            <i class="iconfont nav_right">&#xe697;</i>\n' +
        '                        </a>\n' +
        '                        <ul class="sub-menu">\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="gateway-filter-list.html?env=dev&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>dev</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="gateway-filter-list.html?env=fat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>fat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="gateway-filter-list.html?env=uat&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>uat</cite>\n' +
        '\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '                            <li>\n' +
        '                                <a _env="true" _href="gateway-filter-list.html?env=pro&gateway=' + gatewayData.name + '">\n' +
        '                                    <i class="iconfont">&#xe6a7;</i>\n' +
        '                                    <cite>pro</cite>\n' +
        '                                </a>\n' +
        '                            </li>\n' +
        '\n' +
        '                        </ul>\n' +
        '                    </li>';

    return gatewayLi;
}